package com.robot.goods.dao;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import com.robot.goods.pojo.Goods;

/**
 * goods数据访问接口
 *
 * @author wuyunbin
 */
public interface GoodsDao extends JpaRepository<Goods, String>, JpaSpecificationExecutor<Goods> {
    /**
     * 通过categoryId查询goods列表并分页
     *
     * @param categoryId
     * @param pageable
     * @return
     */
    public Page<Goods> findAllByCategoryIdAndDeletedAtIsNullOrderByCreatedAtDesc(String categoryId, Pageable pageable);

    /**
     * 通过categoryId和storeId查询goods列表并分页
     *
     * @param categoryId
     * @param storeId
     * @param pageable
     * @return
     */
    public Page<Goods> findAllByCategoryIdAndStoreIdAndDeletedAtIsNullOrderByCreatedAtDesc(String categoryId, String storeId, Pageable pageable);

    /**
     * 通过storeId查询goods列表并分页
     *
     * @param storeId
     * @param pageable
     * @return
     */
    public Page<Goods> findAllByStoreIdAndDeletedAtIsNullOrderByCreatedAtDesc(String storeId, Pageable pageable);

    /**
     * 通过categoryId,onSale,status查询goods列表并分页
     *
     * @param categoryId
     * @param onSale
     * @param status
     * @param pageable
     * @return
     */
    public Page<Goods> findAllByCategoryIdAndOnSaleAndStatusAndDeletedAtIsNullOrderByCreatedAtDesc(String categoryId, String onSale, String status, Pageable pageable);

    /**
     * 通过storeId,onSale,status查询goods列表并分页
     *
     * @param storeId
     * @param onSale
     * @param status
     * @param pageable
     * @return
     */
    public Page<Goods> findAllByStoreIdAndOnSaleAndStatusAndDeletedAtIsNullOrderByCreatedAtDesc(String storeId, String onSale, String status, Pageable pageable);

    /**
     * 通过id和storeId查询goods
     *
     * @param id
     * @param storeId
     * @return
     */
    public Goods findByIdAndStoreIdAndDeletedAtIsNull(String id, String storeId);
}
